package cn.btks.resultintegration.rule.controller;

import cn.btks.commonserver.result.ResultState;
import cn.btks.commonserver.result.StateInfo;
import cn.btks.resultintegration.rule.pojo.AdmittanceValue;
import cn.btks.resultintegration.rule.pojo.ConversionCoefficientStandard;
import cn.btks.resultintegration.rule.pojo.ProductCategory;
import cn.btks.resultintegration.rule.pojo.SubstanceParam;
import cn.btks.resultintegration.rule.repository.AdmittanceValueRepository;
import cn.btks.resultintegration.rule.repository.ConversionCoefficientStandardRepository;
import cn.btks.resultintegration.rule.service.AdmittanceValueService;
import cn.btks.resultintegration.rule.service.ConversionCoefficientStandardService;
import com.netflix.discovery.converters.Auto;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Author lijun
 * @Date 2021/10/15 15:03
 */
@RestController
@RequestMapping("api/v1.0/resultIntegration/rule")
@Api(tags = "规则模块")
@Validated
public class ConversionCoefficientStandardController {

    @Autowired
    ConversionCoefficientStandardService conversionCoefficientStandardService;

    @Autowired
    AdmittanceValueService admittanceValueService;

    @GetMapping("/conversionCoefficientStandard/findAll")
    @ApiOperation("查询所有标煤量（折标系数法）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll() {
        List<ConversionCoefficientStandard> list = conversionCoefficientStandardService.findAll();
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/admittanceValue/findAll")
    @ApiOperation("查询所有标煤量（准入值估算）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findAll1() {
        List<AdmittanceValue> list = admittanceValueService.findAll();
        return list != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), list) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @GetMapping("/admittanceValue/findById/{id}")
    @ApiOperation("根据ID查询标煤量（准入值估算）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState findById(@PathVariable("id") Long id) {
        AdmittanceValue admittanceValue = admittanceValueService.findById(id);
        return admittanceValue != null ? new ResultState(StateInfo.FIND_OK.getCode(),
                StateInfo.FIND_OK.getMsg(), admittanceValue) : new ResultState(StateInfo.FIND_NULL.getCode(),
                StateInfo.FIND_NULL.getMsg());
    }

    @PostMapping("/admittanceValue/save")
    @ApiOperation(value = "新增标煤量（准入值估算）", notes = "新增标煤量（准入值估算）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState save(@RequestBody AdmittanceValue admittanceValue) {
        return admittanceValueService.save(admittanceValue);
    }

    @PutMapping("/admittanceValue/update")
    @ApiOperation(value = "更新标煤量（准入值估算）", notes = "更新标煤量（准入值估算）")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "header", name = "token", value = "token", required = true, dataType = "string")
    })
    public ResultState update(@RequestBody AdmittanceValue admittanceValue) {
        return admittanceValueService.update(admittanceValue);
    }

    @DeleteMapping("/admittanceValue/delete/{id}")
    @ApiOperation("根据ID删除标煤量（准入值估算）信息")
    @ApiImplicitParams({
            @ApiImplicitParam(paramType = "path", name = "id", value = "标煤量（准入值估算）ID", required = true, dataType = "long"),
            @ApiImplicitParam(paramType = "header", name = "token", value = "token密匙", required = true, dataType = "string")
    })
    public ResultState delete(@PathVariable("id") Long id) {
        return admittanceValueService.delete(id);
    }
}
